<%@page import="cn.jhc.bean.MusicBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="cn.jhc.dao.TitleDAO"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<link rel="stylesheet" type="text/css" href="./css/music.css"></link>
<title>乐谱下载</title>
</head>
<body>
	<%
		int CurrentPage = 1;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
		int titleCount = 9;
	%>
	<%
		TitleDAO dao = new TitleDAO();
		dao.setCon(ConnectionFactory.getConnection());
		intPageCount = dao.getMusicCount(titleCount);
		if(intPageCount==0){
			CurrentPage=1;
			intPageCount=1;
		}else{
		if (CurrentPage > intPageCount)
			CurrentPage = intPageCount;
		}
	%>
	<div id="wrapper">
		<jsp:include page="./header.jsp"></jsp:include>
		<div id="address">
			<a>当前位置： 乐谱下载</a>
		</div>
		<div id="box">
			<div class="box_a" align="center"><a>本站提供用户吉他乐谱的下载，但下载需要花费用户积分，积分可在讨论区发帖和回帖获取。</a></div>
			<div class="box_search">
			<div class="search1">
			<form method="post" action="./yuepudownload.jsp?search=no">
				<input type="submit" value="返回">
			</form>
			</div>
			<div class="search2">
			<form method="post" action="./searchMusic.do">
				<input type="submit" value="搜索">
				<input type="text" name="title" value=""></input>
			</form>
			</div>
			</div>
		</div>
		<% 
			String search = request.getParameter("search");
			if(search.equals("no")){
		%>
		<div id="alljita">
			<%
				request.setCharacterEncoding("UTF-8");
				ArrayList<MusicBean> music = new ArrayList<MusicBean>();
				TitleDAO dao2 = new TitleDAO();
				dao2.setCon(ConnectionFactory.getConnection());
				music = dao2.getAllMusic(CurrentPage, titleCount);
				request.setAttribute("allmusic", music);
			%>
				<c:forEach items="${requestScope.allmusic}" var="music" >
				<div class="jita">
					<div class="jita_title2"><a>${music.title}</a></div>
					<div class="jita_image"><a href="yuepudownload2.jsp?id=${music.id}"><img src="UserFiles/Image/${music.imagename}" width="250" height="230"></a></div>
				</div>
				</c:forEach>
		</div>
		<div id="page" align="right">
					<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
					</a> <a href="yuepudownload.jsp?page=<%=1%>&search=no">首页</a>
					<%
						if (CurrentPage > 1) {
					%>
					<a href="yuepudownload.jsp?page=<%=CurrentPage - 1%>&search=no">上一页</a>
					<%
						} else {
					%>
					上一页
					<%
						}
					%>
					<%
						if (CurrentPage >= intPageCount) {
					%>
					下一页
					<%
						} else {
					%>
					<a href="yuepudownload.jsp?page=<%=CurrentPage + 1%>&search=no">下一页</a>
					<%
						}
					%>
					<a href="yuepudownload.jsp?page=<%=intPageCount%>&search=no">末页</a>
				</div>
		<%}else if(search.equals("yes")){ %>
			<div id="alljita">
			<c:forEach items="${requestScope.title}" var="tit">
				<div class="jita">
					<div class="jita_title2"><a>${tit.title}</a></div>
					<div class="jita_image"><a href="yuepudownload2.jsp?id=${tit.id}"><img src="UserFiles/Image/${tit.imagename}" width="250" height="230"></a></div>
				</div>
			</c:forEach>
			</div>
		<%} %>
		<div id="button_bg"></div>
		<div id="line2"></div>
		<div id="copyright">
			<a>&copy;版权所有:金职院蓝调吉他社 </a><a>| </a>
			<div id="admin">
				<a href="houtai_index.jsp">管理员登录</a>
			</div>
		</div>
	</div>
</body>
</html>